*-------------------------------------------------------------------------------------------------------------*
* The Causal Effects of R&D Grants: Evidence from a Regression Discontinuity (Santoleri et al., 2020)
*-------------------------------------------------------------------------------------------------------------*

/// Table 3: The effects on investment

use $data_path/DATA_ALL_FINAL.dta, clear 

* dependent var, treatment var, pre-treatment var
local dvar investment_post_w award fixed_assets_pre_w

* controls for polinomyal orders on both sides of the threshold
global linear    c.rank#i.award
global quadratic c.rank#i.award c.rank#c.rank#i.award

* regression loops reproducing Table 3
est clear
forv i=2/2 {
             eststo: reghdfe `dvar' $linear    if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' i.quintile if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $linear    if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $linear    if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
}
* display results of Table 3 in .txt format
cap erase $output/Table_3.txt $output/Table_3.tex
esttab est* using $output/Table_3.txt, replace star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat(N r2 bic, fmt(0 2 2)) title(Table 3: The effects on investment) mtitles(All All All 10 10 5 5 ) ///
coeflabels(award "Grant") indicate( "Rank x Grant=*award#c.rank" "Rank2 x Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile" ) varwidth(25) nonotes

* display results of Table 3 in .tex format
esttab est* using $output/Table_3.tex, replace star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) stats(N   r2 bic, fmt(0 2 2) labels(N "R-squared" "BIC")) keep(award) ///
coeflabels(award "Grant") mtitles(All All All 10 10 5 5 ) prehead(\begin{table}[htbp]\centering \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \caption{The effects on investment} \begin{tabular}{l*{9}{c}} \toprule) ///
postfoot(\bottomrule \end{tabular}  \end{table}) posthead(\midrule) booktabs nonotes indicate( "Rank $\times$ Grant=*.award#c.rank" "Rank^{2} $\times$ Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile"  ) varwidth(25)




